package test;

//求根节点到叶节点的数字之和：https://leetcode.cn/problems/sum-root-to-leaf-numbers/description/
public class SumNumbers {
	
	public static int ret=0;
	
    public void dfs(TreeNode root,int sum){
        if(root==null) return ;
        //到根节点进行结算
        if(root.left==null&&root.right==null){
            ret+=sum*10+root.val;
            return ;
        }     
        dfs(root.left,sum*10+root.val);
        dfs(root.right,sum*10+root.val);
    }
    public int sumNumbers(TreeNode root) {
        ret=0;
        dfs(root,0);
        return ret;
    }
}
